package com.asp.controller;

import com.asp.dto.*;
import com.asp.entity.Topic;
import com.asp.result.PageResult;
import com.asp.result.Result;
import com.asp.service.InteractService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * author:          ndg
 * date:            2024/1/5
 */
@RestController
@Api(tags = "社区交流相关接口")
@Slf4j
@RequestMapping("/user/interact")
public class InteractController {


    @Autowired
    private InteractService interactService;

    @PostMapping("/add")
    @ApiOperation(value = "用户发布主题")
    public Result addTopic(@RequestBody AddTopicDTO addTopicDTO) {
        log.info("用户发布主题:{}", addTopicDTO);
        interactService.addTopic(addTopicDTO);
        return Result.success();
    }


    @GetMapping("/topic")
    @ApiOperation(value = "主题列表分页展示")
    public Result<PageResult> topicList(TopicPageQueryDTO topicPageQueryDTO) {
        log.info("主题列表展示:{}", topicPageQueryDTO);
        PageResult pageResult = interactService.pageQuery(topicPageQueryDTO);
        return Result.success(pageResult);
    }


    @GetMapping("/topic/{topicId}")
    @ApiOperation(value = "主题详情展示")
    public Result topicDetail(@PathVariable Integer topicId) {
        log.info("主题详情展示：{}", topicId);
        Topic topic = interactService.topicDetail(topicId);
        return Result.success(topic);
    }

    @PostMapping("/replyAdd")
    @ApiOperation(value = "用户发表评论")
    public Result replyAdd(@RequestBody ReplyAddDTO replyAddDTO) {
        log.info("用户发表评论：{}", replyAddDTO);
        interactService.replyAdd(replyAddDTO);
        return Result.success();
    }

    @DeleteMapping("/topicDelete")
    @ApiOperation(value = "用户删除主题")
    public Result topicDelete(Integer topicId) {
        log.info("用户删除主题：{}", topicId);
        interactService.topicDelete(topicId);
        return Result.success();
    }

    @GetMapping("/topic/{topicId}/reply")
    @ApiOperation(value = "评论分页展示")
    public Result<PageResult> topicReply(TopicReplyPageQueryDTO topicReplyPageQueryDTO) {
        log.info("评论分页查询：{}", topicReplyPageQueryDTO);
        PageResult pageResult = interactService.topicReply(topicReplyPageQueryDTO);
        return Result.success(pageResult);
    }


    @PostMapping("/topic/click")
    @ApiOperation(value = "用户主题点赞")
    public Result topicClick(@RequestBody TopicClickDTO topicClickDTO) {
        log.info("用户主题点赞：{}", topicClickDTO);
        interactService.topicClick(topicClickDTO);
        return Result.success();
    }


    @PostMapping("/reply/click")
    @ApiOperation(value = "用户评论点赞")
    public Result replyClick(@RequestBody TopicReplyClickDTO topicReplyClickDTO) {
        log.info("用户评论点赞：{}", topicReplyClickDTO);
        interactService.replyClick(topicReplyClickDTO);
        return Result.success();
    }

    @DeleteMapping("/reply/delete")
    @ApiOperation(value = "用户删除评论")
    public Result replyDelete(@RequestBody ReplyDeleteDTO replyDeleteDTO) {
        log.info("用户删除评论：{}", replyDeleteDTO);
        interactService.replyDelete(replyDeleteDTO);
        return Result.success();
    }

    @DeleteMapping("/topic/unClick")
    @ApiOperation(value = "用户取消主题点赞")
    public Result topicUnClick(@RequestBody TopicClickDTO topicClickDTO) {
        log.info("用户取消主题点赞：{}", topicClickDTO);
        interactService.topicUnClick(topicClickDTO);
        return Result.success();
    }


    @DeleteMapping("/reply/unClick")
    @ApiOperation(value = "用户取消评论点赞")
    public Result replyUnClick(@RequestBody TopicReplyClickDTO topicReplyClickDTO) {
        log.info("用户取消评论点赞：{}", topicReplyClickDTO);
        interactService.replyUnClick(topicReplyClickDTO);
        return Result.success();
    }
}
